<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>天猫商品管理首页</title>
<link rel="stylesheet" href="css/porduct.css">
</head>
<body>
	<div id="Goods">
		<div class="change">
			<div>
				<a href="addGoods.jsp">添加商品</a>
			</div>
		</div>
		<div class="porduct-table">
			<form action="getGoods.do" method="get" enctype="multipart/form-data"> 
				<table border="1" width="1500">
				<legend>关于商品</legend>
					<tr>
						<td>商品id</td>
						<td>商品名</td>
						<td>商品价格</td>
						<td>商品类型</td>
						<td>商品描述</td>
						<td>商品图片</td>
						<td>商品描述</td>
						<td>bealoon</td>
						<td>选择</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</body>
<script src="js/jquery.min.js"></script>
<script>
load();
function load(){
	 	var keyword = " ";
	 	$.ajax({
	 		url:"/shopping/getGoods.do",
	 		type:"GET",
	 		data:{
				"pageNum":1,
	 			"pageSize":10,
	 			"keyword":keyword
	 		},
	 		success:function(data){
	 			console.log(data);
	 			var goods = data.data;
				for(var i = 0;i < goods.length;i++){
	 				var g = goods[i];
	 				var $tr = $("<tr></tr>")
	 				var $input1 = $("<input type='text' name='goodsId' class='goodsId'>").val(g.goodsId);
					var $input2 = $("<input type='text' name='gName' class='gName'>").val(g.gName);
					var $input3 = $("<input type='text' name='gPrice' class='gPrice'>").val(g.gPrice);
	 				var $input4 = $("<input type='text' name='gType' class='gType'>").val(g.gType);
	 				var $input5 = $("<input type='text' name='gIntro' class='gIntro'>").val(g.gIntro);
	 				var $input6 = $("<input type='text' name='gIf' class='gIf'>").val(g.gIf);
	 				var $input7 = $("<input type='text' name='busineId' class='busineId'>").val(g.busineId);
	 				var $input8 = $("<input type='button' value='删除'>").click(function(){
	 					$.ajax({
	 						url:"/shopping/updateGoods.do",
	 						type:"GET",
	 						data:{
	 							"goodsId":g.goodsId,
	 							"keyword":"删除"
	 						},
	 						success:function(data){
	 							alert("删除成功");
	 						}
	 					});
	 				});
	 				var $input9 = $("<input type='button' value='修改'>").click(function(event){
	 					
	 					$input9.val("确认").click(function(){
	 						var gName = $(".gName").val();
	 						var gPrice = $(".gPrice").val();
	 						var gType = $(".gType").val();
	 						var gIntro = $(".gIntro").val();
	 						var gIf = $(".gIf").val();
	 						var busineId = $(".busineId").val();
	 						$.ajax({
	 							url:"/shopping/updateGoods.do",
	 							type:"GET",
	 							data:{
	 								"goodsId":g.goodsId,
	 								"gName":gName,
	 								"gPrice":gPrice,
	 								"gType":gType,
	 								"gIntro":gIntro,
	 								"gIf":gIf,
	  								"busineId":busineId
	 							},
	  							success:function(data){
	 							alert("更改成功");
	  							}	
	 						});
	 					});
	 				});
	 				
	 				var $td1 = $("<td></td>").append($input1);
		 			var $td2 = $("<td></td>").append($input2);
		 			var $td3 = $("<td></td>").append($input3);
		 			var $td4 = $("<td></td>").append($input4);
		 			var $td5 = $("<td></td>").append($input5);
		 			var $td6 = $("<td></td>").append($input6);
		 			var $td8 = $("<td></td>").append($input8,$input9);
		 			$tr.append($td1,$td2,$td3,$td4,$td5,$td6,$td8);
					$("table").append($tr);
	 			}
	 		}
	 	})
	 	$("input").css({
	 		width:"80px"
	 	})
	 }
</script>
</html>